package org.raymond.iworks.study.mq.kafka.consumer;

import lombok.extern.slf4j.Slf4j;
import org.raymond.iworks.study.mq.kafka.common.Foo2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
@Slf4j
@Component
public class Sample3Consumer {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    @KafkaListener(id = "fooGroup2", topics = "topic2")
    public void listen1(List<Foo2> foos) throws IOException {
        log.info("Received: " + foos);
        foos.forEach(f -> kafkaTemplate.send("topic3", f.getFoo().toUpperCase()));
        log.info("Messages sent, hit Enter to commit tx");
        System.in.read();
    }
}
